<template>
  <el-dialog
      :title="!dataForm.emrXyId ? '新增' : '修改'"
      :close-on-click-modal="false"
      :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="80px">
<el-form-item label="病历节点编号" prop="emrJdId">
  <el-input v-model="dataForm.emrJdId" placeholder="病历节点编号"></el-input>

</el-form-item>
<el-form-item label="就诊时间" prop="emrXyDate">
  <el-input v-model="dataForm.emrXyDate" placeholder=""></el-input>

</el-form-item>
<el-form-item label="分诊科室" prop="emrXyKs">
  <el-input v-model="dataForm.emrXyKs" placeholder="分诊科室"></el-input>

</el-form-item>
<el-form-item label="过敏信息" prop="emrXyGm">
  <el-input v-model="dataForm.emrXyGm" placeholder="过敏信息"></el-input>

</el-form-item>
<el-form-item label="主诉" prop="emrXyMain">
  <el-input v-model="dataForm.emrXyMain" placeholder="主诉"></el-input>

</el-form-item>
<el-form-item label="现病史" prop="emrXyNow">
  <el-input v-model="dataForm.emrXyNow" placeholder="现病史"></el-input>

</el-form-item>
<el-form-item label="既往史" prop="emrXyBefore">
  <el-input v-model="dataForm.emrXyBefore" placeholder="既往史"></el-input>

</el-form-item>
<el-form-item label="体温" prop="emrXyTem">
  <el-input v-model="dataForm.emrXyTem" placeholder="体温"></el-input>

</el-form-item>
<el-form-item label="脉搏" prop="emrXyPluse">
  <el-input v-model="dataForm.emrXyPluse" placeholder="脉搏"></el-input>

</el-form-item>
<el-form-item label="呼吸" prop="emrXyBreath">
  <el-input v-model="dataForm.emrXyBreath" placeholder="呼吸"></el-input>

</el-form-item>
<el-form-item label="血压" prop="emrXyPress">
  <el-input v-model="dataForm.emrXyPress" placeholder="血压"></el-input>

</el-form-item>
<el-form-item label="检查资料" prop="emrXyCheck">
  <el-input v-model="dataForm.emrXyCheck" placeholder="检查资料"></el-input>

</el-form-item>
<el-form-item label="处理人编号" prop="emrXyDeal">
  <el-input v-model="dataForm.emrXyDeal" placeholder="处理人编号"></el-input>

</el-form-item>
<el-form-item label="处理人编号" prop="emrYsId">
  <el-input v-model="dataForm.emrYsId" placeholder="处理人编号"></el-input>

</el-form-item>
<el-form-item label="处理人姓名" prop="emrYsName">
  <el-input v-model="dataForm.emrYsName" placeholder="处理人姓名"></el-input>

</el-form-item>
<el-form-item label="病历原件" prop="emrXyImg">
  <el-input v-model="dataForm.emrXyImg" placeholder="病历原件"></el-input>

</el-form-item>
<el-form-item label="附加照片" prop="emrXyImgs">
  <el-input v-model="dataForm.emrXyImgs" placeholder="附加照片"></el-input>

</el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          emrXyId: 0,
          emrJdId: '',
          emrXyDate: '',
          emrXyKs: '',
          emrXyGm: '',
          emrXyMain: '',
          emrXyNow: '',
          emrXyBefore: '',
          emrXyTem: '',
          emrXyPluse: '',
          emrXyBreath: '',
          emrXyPress: '',
          emrXyCheck: '',
          emrXyDeal: '',
          emrYsId: '',
          emrYsName: '',
          emrXyImg: '',
          emrXyImgs: ''
        },
        dataRule: {
          emrJdId: [
            { required: true, message: '病历节点编号不能为空', trigger: 'blur' }
          ],
          emrXyDate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          emrXyKs: [
            { required: true, message: '分诊科室不能为空', trigger: 'blur' }
          ],
          emrXyGm: [
            { required: true, message: '过敏信息不能为空', trigger: 'blur' }
          ],
          emrXyMain: [
            { required: true, message: '主诉不能为空', trigger: 'blur' }
          ],
          emrXyNow: [
            { required: true, message: '现病史不能为空', trigger: 'blur' }
          ],
          emrXyBefore: [
            { required: true, message: '既往史不能为空', trigger: 'blur' }
          ],
          emrXyTem: [
            { required: true, message: '体温不能为空', trigger: 'blur' }
          ],
          emrXyPluse: [
            { required: true, message: '脉搏不能为空', trigger: 'blur' }
          ],
          emrXyBreath: [
            { required: true, message: '呼吸不能为空', trigger: 'blur' }
          ],
          emrXyPress: [
            { required: true, message: '血压不能为空', trigger: 'blur' }
          ],
          emrXyCheck: [
            { required: true, message: '检查资料不能为空', trigger: 'blur' }
          ],
          emrXyDeal: [
            { required: true, message: '处理人编号不能为空', trigger: 'blur' }
          ],
          emrYsId: [
            { required: true, message: '处理人编号不能为空', trigger: 'blur' }
          ],
          emrYsName: [
            { required: true, message: '处理人姓名不能为空', trigger: 'blur' }
          ],
          emrXyImg: [
            { required: true, message: '病历原件不能为空', trigger: 'blur' }
          ],
          emrXyImgs: [
            { required: true, message: '附加照片不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.emrXyId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.emrXyId) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/emrxymodel/info/${this.dataForm.emrXyId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.emrJdId = data.emrXyModel.emrJdId
                this.dataForm.emrXyDate = data.emrXyModel.emrXyDate
                this.dataForm.emrXyKs = data.emrXyModel.emrXyKs
                this.dataForm.emrXyGm = data.emrXyModel.emrXyGm
                this.dataForm.emrXyMain = data.emrXyModel.emrXyMain
                this.dataForm.emrXyNow = data.emrXyModel.emrXyNow
                this.dataForm.emrXyBefore = data.emrXyModel.emrXyBefore
                this.dataForm.emrXyTem = data.emrXyModel.emrXyTem
                this.dataForm.emrXyPluse = data.emrXyModel.emrXyPluse
                this.dataForm.emrXyBreath = data.emrXyModel.emrXyBreath
                this.dataForm.emrXyPress = data.emrXyModel.emrXyPress
                this.dataForm.emrXyCheck = data.emrXyModel.emrXyCheck
                this.dataForm.emrXyDeal = data.emrXyModel.emrXyDeal
                this.dataForm.emrYsId = data.emrXyModel.emrYsId
                this.dataForm.emrYsName = data.emrXyModel.emrYsName
                this.dataForm.emrXyImg = data.emrXyModel.emrXyImg
                this.dataForm.emrXyImgs = data.emrXyModel.emrXyImgs
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/emrxymodel/${!this.dataForm.emrXyId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'emrXyId': this.dataForm.emrXyId || undefined,
                'emrJdId': this.dataForm.emrJdId,
                'emrXyDate': this.dataForm.emrXyDate,
                'emrXyKs': this.dataForm.emrXyKs,
                'emrXyGm': this.dataForm.emrXyGm,
                'emrXyMain': this.dataForm.emrXyMain,
                'emrXyNow': this.dataForm.emrXyNow,
                'emrXyBefore': this.dataForm.emrXyBefore,
                'emrXyTem': this.dataForm.emrXyTem,
                'emrXyPluse': this.dataForm.emrXyPluse,
                'emrXyBreath': this.dataForm.emrXyBreath,
                'emrXyPress': this.dataForm.emrXyPress,
                'emrXyCheck': this.dataForm.emrXyCheck,
                'emrXyDeal': this.dataForm.emrXyDeal,
                'emrYsId': this.dataForm.emrYsId,
                'emrYsName': this.dataForm.emrYsName,
                'emrXyImg': this.dataForm.emrXyImg,
                'emrXyImgs': this.dataForm.emrXyImgs
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
